package com.allwees.bs.configuration;

import com.allwees.bs.module.ums.dao.MessageDao;
import com.allwees.sender.AppSender;
import com.allwees.sender.EMailSender;
import com.allwees.sender.MessageSender;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;


@Configuration
public class SenderConfiguration {

    @Value("${spring.mail.username}")
    private String from;

    @Value("${spring.mail.personal}")
    private String personal;

    @Value("${push.jpush.appKey}")
    private String jpushAppKey;

    @Value("${push.jpush.masterSecret}")
    private String jpushSecret;

    @Bean
    public EMailSender emailSender(JavaMailSender javaMailSender) {
        EMailSender mailSender = new EMailSender();
        mailSender.setSender(javaMailSender);
        mailSender.setFrom(from);
        mailSender.setPersonal(personal);
        return mailSender;
    }

    @Bean(initMethod = "initConfig")
    public AppSender appSender() {
        AppSender appSender = new AppSender();
        appSender.setAppKey(jpushAppKey);
        appSender.setMasterSecret(jpushSecret);
        return appSender;
    }

    @Bean
    public MessageSender messageSender(MessageDao messageDao) {
        MessageSender sender = new MessageSender();
        sender.setMessageDao(messageDao);
        return sender;
    }
}
